package com.qiedan.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qiedan.bean.Item;
import com.qiedan.dto.ItemDto;
import com.qiedan.service.ItemService;
import com.qiedan.mapper.ItemMapper;
import com.qiedan.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 */
@Service
@Slf4j
public class ItemServiceImpl extends ServiceImpl<ItemMapper, Item>
    implements ItemService{

    @Override
    public R<Object> getItemList() {
        QueryWrapper<Item> queryWrapper = new QueryWrapper<>();
        List<Item> itemList = baseMapper.selectList(queryWrapper);
        R<Object> resp = new R<>();
        resp.setCode(1);
        resp.setMsg("获取商品列表");
        resp.add("itemList",itemList);
        return resp;
    }

    @Override
    public R<Object> getItemDetails(Integer iid) {

        log.info("iid: "+iid);
        Item item = baseMapper.selectById(iid);
        ItemDto itemDto = new ItemDto();
        BeanUtils.copyProperties(item,itemDto);
        itemDto.setNum(1);
        R<Object> resp = new R<>();
        resp.add("itemDetail",itemDto);

        return resp;
    }
}




